package com.sa.web.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

public class Page {

	/**
	 * 后台分页获取开始位置
	 */
	public static Integer getStarIndex() {
		 HttpServletRequest request = ServletActionContext.getRequest();
		 Integer pageNumber = request.getParameter("page")==null?0:Integer.parseInt(request.getParameter("page").toString())-1;
		 Integer pageSize = request.getParameter("rows")==null?0:Integer.parseInt(request.getParameter("rows").toString());
		 pageNumber = pageNumber*pageSize==0?0:pageNumber*pageSize;
		return pageNumber;
	}
	
	/**
	 * 后台分页获取每页条数
	 */
	public static Integer getPreIndex() {
		 HttpServletRequest request = ServletActionContext.getRequest();
		 Integer pageSize = request.getParameter("rows")==null?0:Integer.parseInt(request.getParameter("rows").toString());
		return pageSize;
	}

}
